///***********************************************************************
/// GoalRequiredExpertiseBase.cs
/// Owner: joemu
///
/// Provides a .NET Wrapper around the Stored Procedures in the
/// Lazarus database.
///
/// Copyright(c) Microsoft Corporation
///***********************************************************************

using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

using OR.Reuse.Persistence;

using OR.MyGoals.DataAccess;
	   
namespace OR.MyGoals.DataAccess.Generated
{
   /// <summary>
   /// Defines which Technology Focuses are is required to satisfy your various goals.
   /// </summary>
   public class GoalRequiredExpertiseBase : DataAccessBase
   {
      #region Private Property Fields
      
      #endregion
      
      #region Constructors
      
      /// <summary>
	  /// Constructs a new GoalRequiredExpertise and initializes a new SqlConnection.
      /// </summary>
      public GoalRequiredExpertiseBase() : base()
      {
      }
      
      /// <summary>
      /// Constructs a new GoalRequiredExpertise initialized with the specified SqlConnection.
      /// </summary>
      public GoalRequiredExpertiseBase( SqlConnection existingConnection) : base( existingConnection )
      {
      
      }
      
      #endregion
      
      #region Public Methods

      
      /// <summary>
      /// Creates a new GoalRequiredExpertise.
      /// </summary>
      /// <param name="id"></param>
      /// <param name="goalId"></param>
      /// <param name="technologyId"></param>
      /// <param name="created"></param>
      /// <param name="modified"></param>
      public void Create
      (
         out System.Int32 id,
         System.Int32 goalId,
         System.Int32 technologyId,
         out System.DateTime created,
         System.DateTime modified
      )
      {
         
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalRequiredExpertiseCreate]";
         currentCommand.Connection       = this.Connection;
   

         currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
         currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) );
         
				currentCommand.Parameters[ "@id" ].Direction = ParameterDirection.Output;
            currentCommand.Parameters.Add( new SqlParameter( "@goalId", SqlDbType.Int, 4 ) ).Value = goalId;
         currentCommand.Parameters.Add( new SqlParameter( "@technologyId", SqlDbType.Int, 4 ) ).Value = technologyId;
         currentCommand.Parameters.Add( new SqlParameter( "@created", SqlDbType.DateTime, 1 ) );
         
				currentCommand.Parameters[ "@created" ].Direction = ParameterDirection.Output;
            currentCommand.Parameters.Add( new SqlParameter( "@modified", SqlDbType.DateTime, 1 ) ).Value = modified;
         
      
	     if ( Connection.State != ConnectionState.Open ) { Connection.Open(); }
         
         currentCommand.ExecuteNonQuery();
         
         // Dump out the output params.
         id = ( System.Int32 )currentCommand.Parameters[ "@id" ].Value;created = ( System.DateTime )currentCommand.Parameters[ "@created" ].Value;
      
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
      }
   
      /// <summary>
      /// Updates an existing GoalRequiredExpertise matching the specified ID.
      /// </summary>
      /// <param name="id"></param>
      /// <param name="goalId"></param>
      /// <param name="technologyId"></param>
      /// <param name="modified"></param>
      public void Update
      (
         System.Int32 id,
         System.Int32 goalId,
         System.Int32 technologyId,
         System.DateTime modified
      )
      {
         
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalRequiredExpertiseUpdate]";
         currentCommand.Connection       = this.Connection;
   

         currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
         currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) ).Value = id;
         currentCommand.Parameters.Add( new SqlParameter( "@goalId", SqlDbType.Int, 4 ) ).Value = goalId;
         currentCommand.Parameters.Add( new SqlParameter( "@technologyId", SqlDbType.Int, 4 ) ).Value = technologyId;
         currentCommand.Parameters.Add( new SqlParameter( "@modified", SqlDbType.DateTime, 1 ) ).Value = modified;
         
      
	     if ( Connection.State != ConnectionState.Open ) { Connection.Open(); }
         
         currentCommand.ExecuteNonQuery();
         
         // Dump out the output params.
         
      
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
      }
   
      /// <summary>
	  /// Returns a single GoalRequiredExpertise matching the specified ID.
	  /// </summary>
      /// <param name="id"></param>
      /// <returns>DataSet containing matching records.</returns>
      public override DataSet Get
      (
         System.Int32 id
      )
      {
         try
         {
				
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalRequiredExpertiseGet]";
         currentCommand.Connection       = this.Connection;
   

				currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
				currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) ).Value = id;
         
      
			if ( this.Connection.State != ConnectionState.Open ) { this.Connection.Open(); }
            
				SqlDataReader resultReader = currentCommand.ExecuteReader();
	         
				// Dump out the output params.
				
            
            DataSet rtnVal = new DataSet();
            rtnVal.Load( resultReader, LoadOption.OverwriteChanges, "GoalRequiredExpertise" );
            
            resultReader.Close();
            
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
            
            return( rtnVal );
         }
         catch ( SqlException e )
         {
            throw new Exception ( e.Message ); 
         }         
      }
   
      /// <summary>
	  /// Returns a list of GoalRequiredExpertise records.
	  /// </summary>
      public DataSet List()
      {
         try
         {
				
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalRequiredExpertiseList]";
         currentCommand.Connection       = this.Connection;
   

				currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
				
      
			if ( this.Connection.State != ConnectionState.Open ) { this.Connection.Open(); }
            
				SqlDataReader resultReader = currentCommand.ExecuteReader();
	         
				// Dump out the output params.
				
            
            DataSet rtnVal = new DataSet();
            rtnVal.Load( resultReader, LoadOption.OverwriteChanges, "GoalRequiredExpertise" );
            
            resultReader.Close();
            
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
            
            return( rtnVal );
         }
         catch ( SqlException e )
         {
            throw new Exception ( e.Message ); 
         }         
      }
   

	   public override DataTable EmptyTable()
	   {
	   DataTable rtnVal = new DataTable();

	   rtnVal.TableName = "GoalRequiredExpertise";
         
         
			 rtnVal.Columns.Add( new DataColumn( "Id", typeof( System.Int32 ) ) );
			 rtnVal.Columns.Add( new DataColumn( "GoalId", typeof( System.Int32 ) ) );
			 rtnVal.Columns.Add( new DataColumn( "TechnologyId", typeof( System.Int32 ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Created", typeof( System.DateTime ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Modified", typeof( System.DateTime ) ) );

	   return( rtnVal );
	   }

	   #endregion
	}
}
   